Recap of the June meeting
graphicslibrary3D warning
rgllibraryplotlylibrarymagicklibraryCode Surgery - Sales data analysis
28-Jul-2022
Recap of the June meeting
graphics library
3D warning
rgl library
plotly library
magick library
Code Surgery - Sales data analysis
Spatial analysis
Three dimensional objects are very popular but negatively affect the accuracy and speed at which one can interpret a graphic in most cases.
Good for:
Bad for:
graphics library# simple right circular cone
cone <- function(x, y){
sqrt(x ^ 2 + y ^ 2)
}
# prepare variables
x <- y <- seq(-1, 1, length = 30)
z <- outer(x, y, cone)
# plot the 3D surface
persp(x, y, z)
rgl librarylibrary(rgl)
# This is to output a rgl plot in a rmarkdown document.
setupKnitr()
# Add a new column with color to iris
mycolors <- c('royalblue1', 'darkcyan', 'oldlace')
iris$color <- mycolors[ as.numeric(iris$Species) ]
# Plot
plot3d(
x = iris$`Sepal.Length`, y = iris$`Sepal.Width`, z = iris$`Petal.Length`,
col = iris$color,
type = 's',
radius = .1,
xlab="Sepal Length", ylab="Sepal Width", zlab="Petal Length")
# To display in an R Markdown document:
rglwidget()
plotly librarylibrary(plotly) # Data: volcano is provided by plotly # Plot p <- plot_ly(z = volcano, type = "surface") p
rgl + magicklibrary(rgl)
library(magick)
mycolors <- c('royalblue1', 'darkcyan', 'oldlace')
iris$color <- mycolors[ as.numeric(iris$Species) ]
# Static chart
plot3d( iris[,1], iris[,2], iris[,3], col = iris$color, type = "s", radius = .2 )
# We can indicate the axis and the rotation velocity
play3d( spin3d( axis = c(0, 0, 1), rpm = 20), duration = 10 )
# Save as a gif
movie3d(
movie="3dAnimatedScatterplot",
spin3d( axis = c(0, 0, 1), rpm = 7),
duration = 10,
dir = "/content/drive/MyDrive/Colab Notebooks/tb-data-science-talks/2022-07-28/presentation/",
type = "gif",
clean = TRUE)
## NULL